import { apiMemberIndex, apiGetTeamList } from '../../api/index'
import { formatTime } from '../../common/js/timer'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userImg: '',
    userName: '',
    teamList: [],
    team_number: '',
    sum_commission: '',
    isShow: false,
    loads: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    this.getUser()
    this.getTeamList()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {
  },
  getUser () {
    apiMemberIndex().then(
      res => {
        this.setData({
          userInfo: res.data
        })
      }
    )
  },
  getTeamList () {
    apiGetTeamList().then(res => {
      let teamList = res.data.team_list
      teamList.map(item => {
        item.time = formatTime(item.create_time, 'Y-M-D')
        if (item.nick_name.length >= 10) {
          item.nick_name = item.nick_name.substr(0, 10) + '...'
        }
        console.log(item.nick_name.length)
      })
      this.setData({
        teamList,
        team_number: res.data.team_number,
        sum_commission: res.data.sum_commission,
        loads: false
      })
    })
  },
  lookExp () {
    this.setData({
      isShow: true
    })
  },
  isClose () {
    this.setData({
      isShow: false
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh () {
    if (this.data.teamList.length === 0) {
      wx.stopPullDownRefresh()
    }
  }

  // /**
  //  * 页面上拉触底事件的处理函数
  //  */
  // onReachBottom () {

  // }
})
